#include "SuperBlockData.h"

void SuperBlockDataTestCase::testZeroINodes(void) {
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	SuperBlockData sb(da,0);
	delete da;
}
void SuperBlockDataTestCase::testNewDiskSB(void) {
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,6400);
	SuperBlockData sb(da,32);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: DISK_SIZE",(unsigned int)6400,sb.get(SuperBlockData::DISK_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: BLOCK_SIZE",(unsigned int)64,sb.get(SuperBlockData::BLOCK_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: ROOT_INODE",(unsigned int)0,sb.get(SuperBlockData::ROOT_INODE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_BLOCKS_COUNT",(unsigned int)60,sb.get(SuperBlockData::FREE_BLOCKS_COUNT));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_BLOCKS_BLOCK",(unsigned int)1,sb.get(SuperBlockData::FIRST_FREE_BLOCKS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FIRST_FREE_BLOCK_OFFSET",(unsigned int)0,sb.get(SuperBlockData::FIRST_FREE_BLOCK_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_BLOCKS_BLOCK",(unsigned int)39,sb.get(SuperBlockData::LAST_FREE_BLOCKS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_BLOCKS_BLOCK",(unsigned int)14,sb.get(SuperBlockData::LAST_FREE_BLOCK_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: INODE_ARRAY_SIZE",(unsigned int)32,sb.get(SuperBlockData::INODE_ARRAY_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_INODES_COUNT",(unsigned int)32,sb.get(SuperBlockData::FREE_INODES_COUNT));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_INODES_BLOCK",(unsigned int)2,sb.get(SuperBlockData::FIRST_FREE_INODES_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FIRST_FREE_INODE_OFFSET",(unsigned int)0,sb.get(SuperBlockData::FIRST_FREE_INODE_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_INODS_BLOCK",(unsigned int)36,sb.get(SuperBlockData::LAST_FREE_INODS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_INODS_BLOCK",(unsigned int)1,sb.get(SuperBlockData::LAST_FREE_INODE_OFFSET));
	delete da;
}
void SuperBlockDataTestCase::testSB(void) {
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	SuperBlockData* sb=new SuperBlockData(da,3);
	delete sb;
	delete da;
	da=new DiskAbstraction(fs,64,650);
	sb=new SuperBlockData(da,3);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: DISK_SIZE",(unsigned int)640,sb->get(SuperBlockData::DISK_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: BLOCK_SIZE",(unsigned int)64,sb->get(SuperBlockData::BLOCK_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: ROOT_INODE",(unsigned int)0,sb->get(SuperBlockData::ROOT_INODE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_BLOCKS_COUNT",(unsigned int)4,sb->get(SuperBlockData::FREE_BLOCKS_COUNT));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_BLOCKS_BLOCK",(unsigned int)1,sb->get(SuperBlockData::FIRST_FREE_BLOCKS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FIRST_FREE_BLOCK_OFFSET",(unsigned int)0,sb->get(SuperBlockData::FIRST_FREE_BLOCK_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_BLOCKS_BLOCK",(unsigned int)1,sb->get(SuperBlockData::LAST_FREE_BLOCKS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: INODE_ARRAY_SIZE",(unsigned int)3,sb->get(SuperBlockData::INODE_ARRAY_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_INODES_COUNT",(unsigned int)3,sb->get(SuperBlockData::FREE_INODES_COUNT));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_INODES_BLOCK",(unsigned int)2,sb->get(SuperBlockData::FIRST_FREE_INODES_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FIRST_FREE_INODE_OFFSET",(unsigned int)0,sb->get(SuperBlockData::FIRST_FREE_INODE_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_INODS_BLOCK",(unsigned int)2,sb->get(SuperBlockData::LAST_FREE_INODS_BLOCK));
	delete sb;
	delete da;
}
void SuperBlockDataTestCase::testSetterGetters(void) {
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	SuperBlockData sb(da,3);
	sb.set(SuperBlockData::ROOT_INODE,10);
	sb.set(SuperBlockData::FREE_BLOCKS_COUNT,11);
	sb.set(SuperBlockData::FIRST_FREE_BLOCKS_BLOCK,12);
	sb.set(SuperBlockData::FIRST_FREE_BLOCK_OFFSET,13);
	sb.set(SuperBlockData::LAST_FREE_BLOCKS_BLOCK,14);
	sb.set(SuperBlockData::FREE_INODES_COUNT,16);
	sb.set(SuperBlockData::FIRST_FREE_INODES_BLOCK,17);
	sb.set(SuperBlockData::FIRST_FREE_INODE_OFFSET,18);
	sb.set(SuperBlockData::LAST_FREE_INODS_BLOCK,19);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: DISK_SIZE",(unsigned int)640,sb.get(SuperBlockData::DISK_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: BLOCK_SIZE",(unsigned int)64,sb.get(SuperBlockData::BLOCK_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: ROOT_INODE",(unsigned int)10,sb.get(SuperBlockData::ROOT_INODE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_BLOCKS_COUNT",(unsigned int)11,sb.get(SuperBlockData::FREE_BLOCKS_COUNT));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_BLOCKS_BLOCK",(unsigned int)12,sb.get(SuperBlockData::FIRST_FREE_BLOCKS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FIRST_FREE_BLOCK_OFFSET",(unsigned int)13,sb.get(SuperBlockData::FIRST_FREE_BLOCK_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_BLOCKS_BLOCK",(unsigned int)14,sb.get(SuperBlockData::LAST_FREE_BLOCKS_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: INODE_ARRAY_SIZE",(unsigned int)3,sb.get(SuperBlockData::INODE_ARRAY_SIZE));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_INODES_COUNT",(unsigned int)16,sb.get(SuperBlockData::FREE_INODES_COUNT));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FREE_INODES_BLOCK",(unsigned int)17,sb.get(SuperBlockData::FIRST_FREE_INODES_BLOCK));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: FIRST_FREE_INODE_OFFSET",(unsigned int)18,sb.get(SuperBlockData::FIRST_FREE_INODE_OFFSET));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect after new disk: LAST_FREE_INODS_BLOCK",(unsigned int)19,sb.get(SuperBlockData::LAST_FREE_INODS_BLOCK));
	delete da;
}

void SuperBlockDataTestCase::testInodesArraySizeChange(void){
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	SuperBlockData sb(da,3);
	try{
		sb.set(SuperBlockData::INODE_ARRAY_SIZE,0);
	}catch(Exception ex){
		delete da;
		return;
	}
	CPPUNIT_FAIL("Exception should have been trown on inodes array size set!");
	delete da;
}

void SuperBlockDataTestCase::testBlockSizeChange(void){
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	SuperBlockData sb(da,3);
	try{
		sb.set(SuperBlockData::BLOCK_SIZE,0);
	}catch(Exception ex){
		delete da;
		return;
	}
	CPPUNIT_FAIL("Exception should have been trown on block size set!");
	delete da;
}

void SuperBlockDataTestCase::testDiskSizeChange(void){
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	SuperBlockData sb(da,3);
	try{
		sb.set(SuperBlockData::DISK_SIZE,0);
	}catch(Exception ex){
		delete da;
		return;
	}
	CPPUNIT_FAIL("Exception should have been trown on disk size set!");
	delete da;
}

void SuperBlockDataTestCase::testIllegalInodesArraySize(void){
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,650);
	try{
		SuperBlockData sb(da,30);
	}catch(Exception ex){
		delete da;
		return;
	}
	CPPUNIT_FAIL("Exception should have been trown on illegal inodes array size!");
	delete da;
}

void SuperBlockDataTestCase::testNotEnoughDiskSpace(void){
	string fs("FILE_SYS");
	DiskAbstraction* da=new DiskAbstraction(fs,64,384);
	try{
		SuperBlockData sb(da,3);
	}catch(Exception ex){
		delete da;
		return;
	}
	CPPUNIT_FAIL("Exception should have been trown on illegal disk size!");
	delete da;
}
